package com.company.workflow.controller;

import com.company.oa.common.api.Result;
import com.company.workflow.model.ProcessTemplate;
import com.company.workflow.service.ProcessTemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/process/template")
public class ProcessTemplateController {

    @Autowired
    private ProcessTemplateService processTemplateService;

    @PostMapping
    public Result<ProcessTemplate> saveTemplate(@RequestBody ProcessTemplate template) {
        return Result.success(processTemplateService.saveTemplate(template));
    }

    @GetMapping("/{id}")
    public Result<ProcessTemplate> getTemplate(@PathVariable Long id) {
        return Result.success(processTemplateService.getTemplate(id));
    }

    @GetMapping("/list")
    public Result<List<ProcessTemplate>> listTemplates() {
        return Result.success(processTemplateService.listTemplates());
    }

    @DeleteMapping("/{id}")
    public Result<Boolean> deleteTemplate(@PathVariable Long id) {
        processTemplateService.deleteTemplate(id);
        return Result.success(true);
    }

    @PostMapping("/{id}/deploy")
    public Result<String> deployTemplate(@PathVariable Long id) {
        String deploymentId = processTemplateService.deployTemplate(id);
        return Result.success(deploymentId);
    }
} 